package com.sydsen.imager.elements;

import java.awt.*;

/**
 * @Auther: syh
 * @Date: 2021/11/1
 * @Description:
 */
public class Text extends Element<Text> {
    /**
     * 文本内容
     */
    private String text;
    /**
     * 文本字体
     */
    private Font font;
    /**
     * 文本删除线
     */
    private boolean strikeThrough = false;
    /**
     * 文本下划线
     */
    private boolean underline = false;

    /**
     * 斜体
     */
    private boolean oblique = false;

    /**
     * 文本颜色
     */
    private Color color = new Color(0, 0, 0);   //颜色，默认黑色


    /**
     * 文本自动换行
     */
    private boolean breakLine = false;
    /**
     * 文本换行行数
     */
    private int lines = 1;
    /**
     * 文本换行超出部分替代值
     */
    private String append = "";

    private int lineNumber = 1;

    /**
     * @param text 文本内容
     * @param font Font对象
     * @param x    x坐标
     * @param y    y坐标
     */
    public Text(String text, Font font, int x, int y) {
        this.text = text;
        this.font = font;
        super.x(x);
        super.y(y);
    }

    public Text(String text) {
        this(text, 0, 0);
    }

    public Text(String text, int x, int y) {
        this(text, "阿里巴巴普惠体", 30, x, y);
    }

    /**
     * @param text     文本内容
     * @param fontSize 字号
     * @param x        x坐标
     * @param y        y坐标
     */
    public Text(String text, int fontSize, int x, int y) {
        this(text, "阿里巴巴普惠体", fontSize, x, y);
    }

    /**
     * @param text     文本内容
     * @param fontName 字体名称
     * @param fontSize 字号
     * @param x        x坐标
     * @param y        y坐标
     */
    public Text(String text, String fontName, int fontSize, int x, int y) {
        this(text, new Font(fontName, Font.PLAIN, fontSize), x, y);
    }


    public String text() {
        return text;
    }

    public Text text(String text) {
        this.text = text;
        return this;
    }

    public Font font() {
        return font;
    }

    public Text font(Font font) {
        this.font = font;
        return this;
    }

    public Color color() {
        return color;
    }

    public Text color(Color color) {
        this.color = color;
        return this;
    }

    public boolean strikeThrough() {
        return strikeThrough;
    }


    public Text strikeThrough(boolean strikeThrough) {
        this.strikeThrough = strikeThrough;
        return this;
    }

    public boolean underline() {
        return underline;
    }

    public Text underline(boolean underline) {
        this.underline = underline;
        return this;
    }

    public boolean oblique() {
        return this.oblique;
    }

    public Text oblique(boolean oblique) {
        this.oblique = oblique;
        this.fontStyle(Font.ITALIC);
        return this;
    }

    public boolean rich() {
        return this.strikeThrough
                || this.underline
                || this.oblique;
    }

    public boolean breakLine() {
        return breakLine;
    }

    /**
     * 设置自动换行
     *
     * @param width  最大行宽
     * @param lines
     * @param height
     * @return
     */
    public Text breakLine(int width, int height, int lines) {
        this.breakLine = true;
        this.lines = lines;
        super.width(width);
        super.height(height);
        return this;
    }

    /**
     * 设置自动换行
     *
     * @param width  最大行宽
     * @param lines
     * @param height
     * @return
     */
    public Text breakLine(int width, int height, int lines, String append) {
        this.breakLine = true;
        this.lines = lines;
        this.append = append;
        super.width(width);
        super.height(height);
        return this;
    }

    public int lines() {
        return lines;
    }

    public String append() {
        return append;
    }

    public Text fontSize(int fontSize) {
        Font newFont = new Font(font.getName(), font.getStyle(), fontSize);
        this.font = newFont;
        return this;
    }

    public Text fontStyle(int fontStyle) {
        Font newFont = new Font(font.getName(), fontStyle, font.getSize());
        this.font = newFont;
        return this;
    }

    public Text fontFamily(String fontFamily) {
        Font newFont = new Font(fontFamily, font.getStyle(), font.getSize());
        this.font = newFont;
        return this;
    }

    public int lineNumber() {
        return lineNumber;
    }

    public Text lineNumber(int lineNumber) {
        this.lineNumber = lineNumber;
        return this;
    }
}
